<template>
  <all-game-data-template/>
</template>

<script>
    import AllGameDataTemplate from "../../pageTemplate/allGameDataTemplate";

    import {mapActions,mapGetters} from 'vuex';

    export default {
      components: {
        AllGameDataTemplate},
      data() {
            return {}
        },
      created(){
        //setInterval(this.fetchData,10*1000);
      },
      mounted(){
        this.fetchData();
      },
      computed:{
        ...mapGetters([
          'kpi_monthOwnData'
        ])
      },
      watch: {
        // 如果路由有变化，会再次执行该方法
        '$route': 'fetchData',
        '$store.state.app.gameList': 'fetchData',
        '$store.state.kpi.tableData': 'fetchData'
      },
      methods :{
        ...mapActions([
          'allGame_tableData','allGame_echartsData'
        ]),
        fetchData:function () {
          let list = JSON.parse(localStorage.getItem("gameList"))||this.$store.state.app.gameList;
          let ownkpiList = this.kpi_monthOwnData;
          if(list.length>0 && ownkpiList.length>0){
            list.forEach(item=>{
              ownkpiList.forEach(oitem=>{
                if(item.project===oitem.project){
                  item.kpi = oitem.kpiMonth;
                }
              });
            });
            let game = this.$route.params.id;
            let mList = {statistics:list.filter((item)=>item.type ==='1'),overseas:list.filter((item)=>item.type ==='2')};
            this.allGame_tableData(mList[game]);
            this.allGame_echartsData(mList[game]);
          }

        }
      }
    }

</script>

